# Copyright (c) 2015 ArmyAnt
# 版权所有 (c) 2015 ArmyAnt
#
# Licensed under the BSD License, Version 2.0 (the License); 
# 本软件使用BSD协议保护, 协议版本:2.0
# you may not use this file except in compliance with the License. 
# 使用本开源代码文件的内容, 视为同意协议
# You can read the license content in the file "LICENSE" at the root of this project
# 您可以在本项目的根目录找到名为"LICENSE"的文件, 来阅读协议内容
# You may also obtain a copy of the License at 
# 您也可以在此处获得协议的副本:
# 
#     http://opensource.org/licenses/BSD-3-Clause
# 
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# 除非法律要求或者版权所有者书面同意,本软件在本协议基础上的发布没有任何形式的条件和担保,无论明示的或默许的.
# See the License for the specific language governing permissions and limitations under the License. 
# 请在特定限制或语言管理权限下阅读协议
# This file is the internal source file of this project, is not contained by the closed source release part of this software
# 本文件为内部源码文件, 不会包含在闭源发布的本软件中

cmake_minimum_required(VERSION 3.0)
project(${TAR_NAME})

MESSAGE("The target name is ${TAR_NAME}")

if(TAR_MAC STREQUAL arm)
	set(CMAKE_CXX_COMPILER "arm-linux-gnueabi-g++")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
elseif(TAR_BITS STREQUAL 32)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -m32")
else()
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -m64")
endif()
set(CMAKE_TAR_NAME ${TAR_NAME})

#set(JNI_INCLUDE_DIR $ENV{JAVA_HOME}/include)
#MESSAGE("The JNI directory is ${JNI_INCLUDE_DIR}")
#include_directories(${JNI_INCLUDE_DIR})

MESSAGE("Current platform is ${CMAKE_SYSTEM_NAME}")
IF ((CMAKE_SYSTEM_NAME MATCHES "Windows") OR (CMAKE_SYSTEM_NAME MATCHES "CYGWIN"))
	#include_directories(${JNI_INCLUDE_DIR}/win32)
	add_definitions(
			-DOS_WINDOWS=1
			-D__USE_W32_SOCKETS
	)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
	#include_directories(${JNI_INCLUDE_DIR}/linux)
	add_definitions(
			-DOS_UNIX=1
			-DOS_LINUX=1
	)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
	add_definitions(
			-DOS_UNIX=1
			-DOS_BSD=1
			-DOS_MACOS=1
	)
ELSE ()

ENDIF ((CMAKE_SYSTEM_NAME MATCHES "Windows") OR (CMAKE_SYSTEM_NAME MATCHES "CYGWIN"))

include_directories(external/boost)

if(CMAKE_BUILD_TYPE STREQUAL Release)
    add_definitions(
			-DNDEBUG=1
	)
else()
    add_definitions(
            -DDEBUG=1
    )
endif()

if(TAR_MAC STREQUAL x86)
	add_definitions(
			-D_x86=1
	)
elseif(TAR_MAC STREQUAL arm)
	add_definitions(
			-D_arm=1
	)
else()
endif()

if(TAR_BITS STREQUAL 32)
	add_definitions(
			-D_32BIT=1
	)
else()
	add_definitions(
			-D_64BIT=1
	)
endif()

add_definitions(
	-D_cplusplus=201412L
	-D_CMAKE=1
	-DARMYANTLIB_EXPORTS
        -DBOOST_ALL_NO_LIB
)

set(CXX_SOURCE_FILES
        src/base/ArmyAntLib.cpp
        src/tool/AAString.cpp
		src/tool/AALog.cpp
        src/data/AAAes.cpp
        src/data/AABinary.cpp
        src/data/AAJson.cpp
        src/io/AAIStream.cpp
        src/io/AAIStream_File.cpp
        src/io/AAIStream_Memory.cpp
		src/io/AASocket.cpp
		src/io/AASqlClient.cpp
        src/io/C_AAStream.cpp
        src/algorithm/C_AANeuron.cpp
        src/algorithm/AASqlStructs.cpp)

set(TEST_CXX_SOURCE_FILES
        ${CXX_SOURCE_FILES}
		test/main.cpp
)

#LINK_DIRECTORIES(external/boost/stage/lib/)


if(LINK_TYPE STREQUAL static)
	add_library(${CMAKE_TAR_NAME} STATIC ${CXX_SOURCE_FILES})
elseif(LINK_TYPE STREQUAL dynamic)
	add_library(${CMAKE_TAR_NAME} SHARED ${CXX_SOURCE_FILES})
else()
	add_executable(${CMAKE_TAR_NAME} ${TEST_CXX_SOURCE_FILES})
endif()

TARGET_LINK_LIBRARIES(${CMAKE_TAR_NAME} boost_system)

MESSAGE("The binary directory is ${PROJECT_BINARY_DIR}")

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY  bin/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  bin/)

SET_TARGET_PROPERTIES(${CMAKE_TAR_NAME} PROPERTIES OUTPUT_NAME ${TAR_NAME})
